This page last changed on May 18, 2009 by scytacki.

Installing git with macports

1 Install an up-to-date Apple Developer Tools

Install an up-to-date Apple Developer Tools if you don't have it already installed.

A copy of the Apple Developer Tools available at the time your computer was manufactured is available on a second DVD that came with the copy of the original OS.

You can download an up-to-date Apple Developer Tools by registering for a free account Apple Developer Connection account here: http://connect.apple.com. The download is about 1GB.

Apple Developer Tools installs the gcc toolchain which is needed for compiling any new native C or C++, libraries.

1.1 Install MacPorts

Installation instructions for MacPorts are here: http://www.macports.org/install.php

After installing MacPorts the path /opt/local/bin/port should exist. Running the command which port in a shell should produce this response:

$ which port
/opt/local/bin/port

Add /opt/local/bin to your PATH environment variable if it does not already contain this path.

If you use bash you can add /opt/local/bin to the end of your PATH environmental variable in your ~/.profile or ~/.bash_profile file with a statement like his:

export PATH=$PATH:/opt/local/bin

Install git using Macports

#
# Git setup and configuration on Mac
# adapted from: http://arthurkoziel.com/2008/05/02/git-configuration/
#

# first install macports if you don't have it installed
#
#   http://guide.macports.org/#installing.macports

# make sure your local ports tree is up-to-date

sudo port selfupdate

# find out what version of git is available

port search git-core

# list the port variants available for git

port variants git-core

# install git and add the variants git-svn and git bash completion scripts

sudo port install git-core +svn+bash_completion

# you can add "+doc+gitweb" to get the html form of the documentation
# and the web application that will serve git

# Install bash completion:

cp /opt/local/etc/bash_completion.d/git ~/.git-bash-completion.sh
echo "[ -f ~/.git-bash-completion.sh ] && . ~/.git-bash-completion.sh" >> ~/.profile
. ~/.profile

# If you've already installed git using ports and want to know if there 
# is a newer version of git available

sudo port selfupdate
port outdated git-core

# Installing a newer version of git
# The old version is de-activated but will stay installed so it is 
# easy to deactivate the newer version and activate the older version 
# if that proves necessary.

sudo update git-core +svn+bash_completion

# Git configuration

# List of configuration variables:

git config --help

# list your current global git config properties

git config --global -l

# Global ignore file:

echo ".DS_Store" >> ~/.gitignore
git config --global core.excludesfile ~/.gitignore

# SVN-like shortcuts for often used commands:

git config --global alias.st status
git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.br branch

# Information about the author/commiter:

git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com

# If you want git to send patches via mail from git:

git config --global sendemail.smtpserver smtp.my-isp.com

# Colorized output:

git config --global color.branch auto
git config --global color.diff auto
git config --global color.interactive auto
git config --global color.status auto

# TextMate as the default editor:

git config --global core.editor "mate -w"

# Opendiff (FileMerge) to resolve merge conflicts:

git config --global merge.tool opendiff

# Change the font in gitk: 
# Open ~/.gitk and add:

set mainfont {Monaco 12}
set textfont {Monaco 12}
set uifont {Monaco 12}

Two remarks after I installed git:

1) MacPorts requires Xcode, and if you don't have it you get unhelpful error messages. I lost Xcode after upgrading to 10.5 without realizing it. Tto get it if you don't have it, get a free ADC account and find it at http://developer.apple.com/tools/xcode/

2) Some part of the install procedure created a .bach_profile file for me, which caused my .bash_login file to stop being read. I copied everything over to the new .bash_profile file and everything worked again.

Posted by sfentress at Nov 20, 2008 19:10

Not sure if this is similar to Sam's problem above, but after installing git I had some trouble with macports when I tried to install Ruby 1.9. After some help, I found that I had a .bash_profile file with only one line. I added the following above it:

source ~/.profile

Now macports is running just fine.

Posted by abean at Mar 17, 2009 11:06

Yes there is a step in the above instructions that sets up the git bash completion by putting it in the .bash_profile file. You should only have one .profile or .bash_profile but not both. Some programs automatically appear to create and edit the .profile file so it seems like the better file to use. I'll updated the script above to reflect this.

Posted by scytacki at May 18, 2009 20:13

If you want your prompt to include the git branch then you'll want to add something like:
PS1='\h \W$(__git_ps1 " (%s)")\$ '
to your .profile or .bash_profile
this was described in a comment of the git completion script

Posted by scytacki at May 18, 2009 20:25
Document generated by Confluence on Jan 27, 2014 16:56